import request from '@/utils/request'
export const getUser = () => {
  return async (dispatch) => {
    const res = await request.get('/user')
    console.log(res)
    dispatch(savaUser(res.data))
  }
}
export const savaUser = (payload) => {
  return {
    type: 'profile/user',
    payload,
  }
}
export const getProfile = () => {
  return async (dispatch) => {
    const res = await request.get('/user/profile')
    dispatch(saveProfile(res.data))
  }
}
export const saveProfile = (payload) => {
  return {
    type: 'sava/profile',
    payload,
  }
}
export const updateProfile = (data) => {
  return async (dispatch) => {
    await request.patch('/user/profile', data)
    dispatch(getProfile())
  }
}

export const updatePhoto = (fd) => {
  return async (dispatch) => {
    await request.patch('/user/photo', fd)
    dispatch(getProfile())
  }
}
